package com.gxuwz.service.impl;

import com.gxuwz.dao.DepartmentDao;
import com.gxuwz.entity.Department;
import com.gxuwz.entity.vo.PageVo;
import com.gxuwz.result.PageInfo;
import com.gxuwz.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentDao departmentDao;

    public PageVo getDepartmentList(Department department, PageInfo pageInfo) {
        if(department == null){
            return departmentDao.selectDepartmentAll(null,pageInfo);
        }
        String depName = department.getDepName();
        String depID = department.getDepID();
        if( (depName!=null && !depName.equals("")) || (depID!= null && !depID.equals("")) ){
            return departmentDao.selectDepartmentAll(department, pageInfo);
        } else {
            return departmentDao.selectDepartmentAll(null,pageInfo);
        }
    }

    public Department getDepartmentOne(String depId) {
        Department department = departmentDao.selectDepartmentByID(depId);
        return department;
    }

    public boolean addDepartmentInfo(Department department) {
        int i = departmentDao.insertDepartment(department);
        boolean flag = i > 0 ? true : false;
        return flag;
    }

    public boolean updateDepartmentInfo(Department department,String oldId) {
        int i = departmentDao.updateDepartment(department,oldId);
        boolean flag = i > 0 ? true : false;
        return flag;
    }

    public boolean deleteDepartmentOne(String depId) {
        int i = departmentDao.deleteDepartmentById(depId);
        boolean flag = i > 0 ? true : false;
        return flag;
    }

    public List<String> selectDepartmentIds() {
        List<String> ids = departmentDao.selectDepartmentIds();
        return ids;
    }

    public List<Department> getDepartmentIDAndName() {
        List<Department> departments = departmentDao.selectDepartmentIDAndName();
        return departments;
    }
}
